from common.base_page import BasePage
from time import sleep
from test_datas.string_data import *
from page_locators.login_page_locators import LoginPageLocators as LPL
from page_objects.role_manage_page import RoleManage as RM
from test_datas.pic_data import *
from page_locators.user_right_manage_page_locators import UserRightManageLocators as URML

class UserRightManage(BasePage):

    def __init__(self,driver):
        super().__init__(driver)
        self.rm = RM(driver)

    def click_user_right_manage(self):
        self.click(LPL.user_right_manage, '用户权限管理定位点击')
        sleep(1)

    def input_user_name(self):
        self.input(URML.query_sub, "test_user1", "查询输入框定位输入")
        sleep(1)

    def add_role(self):
        self.rm.click_role_manage()  # 点击角色管理
        self.rm.add_role()  # 添加角色
        self.click_user_right_manage()  # 点击进入用户权限管理菜单

    def click_assign_roles(self):
        self.add_role()  # 添加角色
        self.click(URML.assign_roles, "用户权限管理test_user1的分配角色按钮定位")
        sleep(1)

    def check_and_sure(self):
        self.click(URML.check_teacher, "勾选新添加的角色")
        self.click(URML.sure, "确定按钮定位点击")
        sleep(1)

    def assign_roles(self):
        self.click_assign_roles()   # 添加角色并点击分配角色
        self.check_and_sure()  # 点击选择添加的角色

    def into_teacher_info_manage(self):
        self.click(URML.worktable, "我的工作台定位点击")
        self.click(URML.teacher_info_app, "教职工信息管理应用定位点击")
        self.click(URML.teacher_info_menu, "教职工信息管理菜单点击")

    def delete_teacher(self):
        self.click(URML.delete_teacher, "教师列表第一条数据删除按钮")
        self.click(URML.continue_delete, "继续删除按钮点击")
        self.click(URML.knowed, "勾选我已知晓")
        self.click(URML.delete, '点击删除按钮')

    def into_user_manage(self):
        self.click(URML.worktable, "我的工作台定位点击")
        self.click(LPL.application, '用户中心应用定位点击')
        sleep(1)
        self.click_user_right_manage()

    def delete_userinfo(self):
        self.into_teacher_info_manage()
        self.input(URML.input_query, "test_name1", "查询输入框定位输入")
        self.delete_teacher()
        self.into_user_manage()

    def click_batch_assign_roles(self):
        self.click(URML.batch_assign_roles, "批量分配角色点击")

    def check_all_user(self):
        self.click(URML.all_check, "全部勾选框")

    def check_all_click_batch_assign_roles(self):
        sleep(5)
        self.check_all_user()
        sleep(2)
        self.click_batch_assign_roles()


    def batch_deletion_users(self):
        self.into_teacher_info_manage()
        sleep(1)
        self.click(URML.first_check, "勾选教职工信息管理列表的test_name1")
        self.click(URML.second_check, "勾选教职工信息管理列表的test_name2")
        self.click(URML.third_check, "勾选教职工信息管理列表的test_name3")
        self.click(URML.fourth_check, "勾选教职工信息管理列表的test_name4")
        sleep(1)
        self.click(URML.batch_deletion, "批量删除点击")
        self.click(URML.continue_delete, "继续删除按钮点击")
        self.click(URML.knowed1, "勾选我已知晓")
        self.click(URML.delete, '点击删除按钮')

    def check_first_and_second(self):
        self.click(URML.first_check, "勾选列表第一条")
        self.click(URML.second_check, "勾选列表第二条")
        self.click_batch_assign_roles()

    def batch_assign_roles(self):
        self.click_user_right_manage()  # 用户权限管理定位点击
        sleep(1)
        self.click(URML.user1, "勾选用户权限管理的test_user1")
        self.click(URML.user2, "勾选用户权限管理的test_user1")
        self.click(URML.user3, "勾选用户权限管理的test_user1")
        self.click(URML.user4, "勾选用户权限管理的test_user1")
        sleep(1)
        self.click_batch_assign_roles()  # 点击批量分配角色
        sleep(1)
        self.check_and_sure()  # 分配角色

    def batch_delete_users(self):
        self.batch_deletion_users()  # 批量删除

    def delete_role1(self):
        self.rm.click_role_manage()
        self.click(URML.delete_sub2, "测试角色1的删除按钮点击")
        self.click(URML.sure_delete, "系统提示确认删除按钮")